package com.wondertek.poms.dao.po;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.wondertek.poms.common.constant.CurrentUser;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Proxy;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Data
@Entity
@Table(name = "CHANNEL_INFO_PACKAGE")
@DynamicUpdate
@DynamicInsert
@Proxy(lazy = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ChannelInfoPackage implements Serializable {

    private static final long serialVersionUID = -1575733357296384459L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "CHANNEL_INFO_PACKAGE_SEQ")
    @SequenceGenerator(name = "CHANNEL_INFO_PACKAGE_SEQ", allocationSize = 1, sequenceName = "CHANNEL_INFO_PACKAGE_SEQ")
    private Long id;

    @Column(name = "CHANNEL_ID")
    private String channelId;

    @Column(name = "CHANNEL_NAME")
    private String channelName;

    @Column(name = "CHANNEL_PACKAGE_ID")
    private Long channelPackageId;

    @Column(name = "OPERATOR")
    private String operator;

    @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name="CREATE_TIME")
    private Date createTime;

    public static void putTimeAndUser(ChannelInfoPackage channelInfoPackage){
        channelInfoPackage.setCreateTime(new Date());
        channelInfoPackage.setOperator(CurrentUser.currUserName());
    }
}
